#include "label.h"

Label::Label(QWidget* parent)
    : QLabel(parent)
{}

void Label::enterEvent(QEvent *event)
{
    (void)event;
    qDebug() << "鼠标进入";
}

void Label::leaveEvent(QEvent *event)
{
    (void)event;
    qDebug() << "鼠标离开";
}

void Label::mousePressEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        qDebug() << "按下鼠标左键";
    }
    else if(event->button() == Qt::RightButton)
    {
        qDebug() << "按下鼠标右键";
    }
    //    qDebug() << "鼠标按下,当前位置: " << event->x() << ", " << event->y();
    // globalX 和 globalY 是以屏幕左上角为原点，获取的坐标
    qDebug() << "鼠标按下,当前位置: " << event->globalX() << ", " << event->globalY();
}

void Label::mouseReleaseEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        qDebug() << "鼠标左键被释放";
    }
    else if(event->button() == Qt::RightButton)
    {
        qDebug() << "鼠标右键被释放";
    }
}

void Label::mouseDoubleClickEvent(QMouseEvent *event)
{
    if(event->button() == Qt::LeftButton)
    {
        qDebug() << "鼠标左键双击";
    }
    else if(event->button() == Qt::RightButton)
    {
        qDebug() << "鼠标右键双击";
    }
}


